<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

    /**
     * Constructor de la clase makinita.
     * @param array $entrada
     * @param array $reglas
     * @return boolean $error
     */

     
class sfTdModelDate extends sfTdModelBase{
    
    /**
     * Constructor.
     *
     * Available options:
     *
     *  * id_format:       The format for the generated HTML id attributes (%s by default)
     *  * is_hidden:       true if the form widget must be hidden, false otherwise (false by default)
     *  * default:         The default value to use when rendering the widget
     *  * title:           The title to use when the widget is rendered
     *  * link:            The link of the widget
     *  * dateFormat:      The format for the date
     *  * titleFormat:     The format for the title
     * @param array $options     An array of options
     * @param array $attributes  An array of default HTML attributes
     *
     * @see sfWidget
     */
    public function __construct($options = array(), $attributes = array())
    {
      $this->addOption('dateFormat', 'd/m/y');     
      $this->addOption('titleFormat', 'd/m/y H:i:s');           
      parent::__construct($options, $attributes);
    }    
    
    
    
    public function isModelTd() {
        return true;
    }

    public function setDateFormat($dateFormat) {
        $this->dateFormat = $dateFormat;
    }
    
    
    public function render($content = '') {
        
        $value = $this->parent->values[$this->getOption('name')];
        if(!$this->isHidden())
        {
            if($value != '0000-00-00 00:00:00' and $value != null)
            {
                $dateTime = DateTime::createFromFormat("Y-m-d H:i:s", $value);
                $output = $dateTime->format($this->getOption('dateFormat'));
                $title = $dateTime->format($this->getOption('titleFormat'));
            }
            else
            {
                $title = '';
                $output = '--/--/--';  //no hint
            }
                
            $this->setAttribute('title', $title);
            return parent::render($output);
        } else 
        {
            return '';
        }    
        
    }

}


?>
